package com.example.bailin.giftsay.main;

import android.graphics.drawable.Drawable;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.bailin.giftsay.R;
import com.example.bailin.giftsay.baseclass.BaseActivity;
import com.example.bailin.giftsay.guide.GuideFragment;
import com.example.bailin.giftsay.hot.HotFragment;
import com.example.bailin.giftsay.me.MeFragment;
import com.example.bailin.giftsay.sort.SortFragment;

public class MainActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener {


    @Override
    protected int setLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        RadioGroup rg = bindView(R.id.rg_id);
        rg.setOnCheckedChangeListener(this);
        rg.check(R.id.rb_giftsay);

        RadioButton rbGiftSay = bindView(R.id.rb_giftsay);
        Drawable dbGiftSay = getResources().getDrawable(R.drawable.selector_giftsay);
        dbGiftSay.setBounds(0, 0, 70, 70);
        rbGiftSay.setCompoundDrawables(null, dbGiftSay, null, null);

        RadioButton rbHot = bindView(R.id.rb_hot);
        Drawable dbHot = getResources().getDrawable(R.drawable.selector_hot);
        dbHot.setBounds(0, 0, 70, 70);
        rbHot.setCompoundDrawables(null, dbHot, null, null);

        RadioButton rbStor = bindView(R.id.rb_stor);
        Drawable dbStor = getResources().getDrawable(R.drawable.selector_stor);
        dbStor.setBounds(0, 0, 70, 70);
        rbStor.setCompoundDrawables(null, dbStor, null, null);

        RadioButton rbMe = bindView(R.id.rb_me);
        Drawable dbMe = getResources().getDrawable(R.drawable.selector_me);
        dbMe.setBounds(0, 0, 70, 70);
        rbMe.setCompoundDrawables(null, dbMe, null, null);
    }

    @Override
    protected void initData() {

    }


    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        switch (checkedId) {
            case R.id.rb_giftsay:
                Log.e("MainActivity", "GuideFragment");
                fragmentTransaction.replace(R.id.fragment_id, new GuideFragment());
                break;
            case R.id.rb_hot:
                fragmentTransaction.replace(R.id.fragment_id, new HotFragment());
                break;
            case R.id.rb_stor:
                fragmentTransaction.replace(R.id.fragment_id, new SortFragment());
                break;
            case R.id.rb_me:
                fragmentTransaction.replace(R.id.fragment_id, new MeFragment());
                break;
        }
        fragmentTransaction.commit();
    }
}
